//
//  WechatAvatarViewController.m
//  CoachsBook
//
//  Created by MaBookPro on 2022/8/26.
//

#import "WechatAvatarViewController.h"
#import "JhtBannerView.h"
#import "WechatHeadImgCell.h"

@interface WechatAvatarViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView *_Tabview;
    WechatHeadImgCell *Cell;
}

@end

@implementation WechatAvatarViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = rgba(245, 245, 255, 1);
    self.navigationController.navigationBar.hidden = YES;
    NavigationHeadView *navgationheadv = [[NavigationHeadView alloc]initWithFrame:CGRectMake(0, 0, APPwidth, SafeAreaTopHight)];
    navgationheadv.backgroundColor = [UIColor whiteColor];
    navgationheadv.titlelabel.text = @"微信头像";
    navgationheadv.titlelabel.textColor  = [UIColor blackColor];
    [navgationheadv.backbtn addTarget:self action:@selector(returnback) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:navgationheadv];
    
    
    [self CreatListUI];

}
-(void)CreatListUI{
    UIView *header = [[UIView alloc]initWithFrame:CGRectMake(0, SafeAreaTopHight, APPwidth, 80)];
    header.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:header];

    NSArray *OrderArr = @[@"标准头像",@"单自定义头像"];
    for (int i = 0; i < OrderArr.count; i++) {
        UIButton *orderBtn = [[UIButton alloc]initWithFrame:CGRectMake(APPwidth/2*i + APPwidth/38 *(5-3*i), 15, APPwidth/19 *6, 45)];
        [orderBtn setTitle:OrderArr[i] forState:0];
        [orderBtn setBackgroundColor:rgba(226, 239, 255, 1)];
        orderBtn.contentHorizontalAlignment = 0;
        [orderBtn setTitleColor:rgba(51, 51, 51, 1) forState:0];
        orderBtn.titleLabel.font = [UIFont systemFontOfSize:16];
        orderBtn.layer.cornerRadius = 45/2;
        [header addSubview:orderBtn];
    }
    
    JhtBannerView *bannerView = [[JhtBannerView alloc] initWithFrame:CGRectMake(0, header.height+header.y, APPwidth,260)];
    [bannerView clickScrollViewInsideCardView:^(NSInteger index) {
        NSLog(@"点击第%ld张卡片啦！", (long)index);
    }];
    [self.view addSubview:bannerView];
    
    // 假数据
    NSArray *array = @[@"image_1",
                       @"image_2",
                       @"image_3",
                       @"image_4",
                       @"image_5"
                       ];
    bannerView.placeholderImageName = @"placeholder";
    
    [bannerView setImageArray:array];
    
    
    
    //bottomview
    
    UIView *bottomV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, APPwidth, 150)];
    bottomV.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bottomV];
    
    NSArray *bottomArr = @[@"保存头像",@"更换照片"];
    
    for (int i = 0; i < bottomArr.count; i ++) {
        UIButton *bmBtn = [[UIButton alloc]initWithFrame:CGRectMake(15, 15+i*10+i*45, APPwidth-30, 45)];
        [bmBtn setTitle:bottomArr[i] forState:0];
        bmBtn.contentHorizontalAlignment = 0;
        [bmBtn setTitleColor:rgba(22, 120, 255, 1) forState:0];
        bmBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        bmBtn.layer.cornerRadius = 45/2;
        bmBtn.layer.borderWidth = 1;
        bmBtn.layer.borderColor = rgba(22, 120, 255, 1).CGColor;
        [bottomV addSubview:bmBtn];
    }
    

    _Tabview  = [[UITableView alloc]initWithFrame:CGRectMake(0, header.height+header.y, APPwidth, APPheight)];
    _Tabview.delegate = self;
    _Tabview.dataSource = self;
    _Tabview.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_Tabview];
    _Tabview.tableHeaderView = bannerView;
    _Tabview.tableFooterView = bottomV;
}
#pragma mark - UITableView DataSource

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 200;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString * str = @"cell";
    
    Cell  = [tableView dequeueReusableCellWithIdentifier:str];
    if (Cell == nil) {
        
        Cell = [[WechatHeadImgCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier:str];
    }
    
    
    Cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return Cell;
}

-(void)returnback{
    
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark -视图即将出现
-(void)viewWillAppear:(BOOL)animated{
        
    ((TabbarController *)self.tabBarController).tabBarView.hidden = YES;
    
}

@end
